package com.ccl.iot.object;

/**
 * 设备IP地址结构
 * 组合式为：	iPart[0].iPart[1].iPart[2].iPart[3]
 * 例如：		192.168.1.1
 */
public class IOTDeviceIP {
	private int iIP = 0;
	private byte iPart[] = new byte[4];
	
	public IOTDeviceIP(int aIP){
		iIP = aIP;
		
		iPart[0] = (byte) (aIP & 0xFF);
		iPart[1] = (byte) ((aIP >> 8) & 0xFF);
		iPart[2] = (byte) ((aIP >> 16) & 0xFF);
		iPart[3] = (byte) ((aIP >> 24) & 0xFF);
	}
	
	public int getIntIP(){
		return iIP;
	}
	
	@Override
	public String toString() {
		return iPart[0] + "." + iPart[1] + "." + iPart[2] + "." + iPart[3];
	}

	@Override
	public boolean equals(Object aIP) {
		if (!super.equals(aIP)){
			if (aIP != null){
				if (aIP instanceof Integer){
					return (Integer)aIP == iIP;
				}else if (aIP instanceof String){
					return aIP.equals(this.toString());
				}
			}
		}else{
			return true;
		}
		
		return false;
	}
}
